﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Genealogy_Builder
{
    public partial class TraitEditor : Form
    {
        public TraitEditor(List<Trait> TraitList)
        {
            InitializeComponent();
            foreach (Trait t in TraitList)
            {
                lbTraits.Items.Add(t);
            }
        }

        public List<Trait> AddTraits()
        {
            ShowDialog();
            List<Trait> LT = new List<Trait>();
            foreach (Trait t in lbTraits.Items)
            {
                LT.Add(t);
            }
            return LT;
        }

        private void lbRemTrait_Click(object sender, EventArgs e)
        {
            if (lbTraits.SelectedItem != null)
            {
                string itmName = lbTraits.SelectedItem.ToString();
                DialogResult result;
                result = MessageBox.Show("Are you sure you want to delete " + itmName + "?", "Remove Trait", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    lbTraits.Items.Remove(lbTraits.SelectedItem);
                }
            }
        }

        private void lbAddTrait_Click(object sender, EventArgs e)
        {
            TraitDialog TD = new TraitDialog();
            if (TD.AddTrait() && TD.newTrait != null)
            {
                lbTraits.Items.Add(TD.newTrait);
            }
        }

    }
}
